home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
- /*******************************************************************************
- colorview.c
- *******************************************************************************/
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <Xm/Xm.h>
- #include <Xm/MenuShell.h>
- #include "UxXt.h"
-
- #include <Xm/List.h>
- #include <Xm/ScrolledW.h>
- #include <Xm/PushB.h>
- #include <Xm/LabelG.h>
- #include <Xm/Text.h>
- #include <Xm/TextF.h>
- #include <Xm/DrawingA.h>
- #include <Xm/DrawnB.h>
- #include <Xm/Frame.h>
- #include <Xm/CascadeB.h>
- #include <Xm/SeparatoG.h>
- #include <Xm/PushBG.h>
- #include <Xm/RowColumn.h>
- #include <Xm/Form.h>
- #include <X11/Shell.h>
-
- /*******************************************************************************
- Includes, Defines, and Global variables from the Declarations Editor:
- *******************************************************************************/
-
- /*------------------------------------------------
- * Visual Edge Software Limited. December 1990.
- *
- * Color view
- *-----------------------------------------------*/
- #include <X11/Xutil.h>
- #include <X11/Xos.h>
- #include <Xm/Protocols.h>
- #include <Xm/AtomMgr.h>
- #include <X11/cursorfont.h>
-
- #include "exinterfmotif.h"
- #include <string.h>
- #include "exglobals.h"
- #include "exbookglo.h"
- #include "exinterf.h"
-
- #define colorview_width 40
- #define colorview_height 45
- static char colorview_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff,
- 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0xff, 0x0f, 0x70, 0x55, 0x55, 0x55,
- 0x0d, 0xb0, 0xaa, 0xaa, 0xaa, 0x0a, 0x70, 0x55, 0x55, 0x55, 0x0d, 0xb0,
- 0xaa, 0xaa, 0xaa, 0x0a, 0x70, 0x55, 0x55, 0x55, 0x0d, 0xb0, 0xaa, 0xaa,
- 0xaa, 0x0a, 0x70, 0x55, 0x55, 0x55, 0x0d, 0xb0, 0xaa, 0xaa, 0xaa, 0x0a,
- 0x70, 0x55, 0x55, 0x55, 0x0d, 0xb0, 0xaa, 0xaa, 0xaa, 0x0a, 0x70, 0x55,
- 0x55, 0x55, 0x0d, 0xb0, 0xaa, 0xaa, 0xaa, 0x0a, 0xf0, 0xff, 0xff, 0xff,
- 0x0f, 0x00, 0x2a, 0x00, 0x54, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x0f, 0x10,
- 0x00, 0x00, 0x00, 0x08, 0xd0, 0xfb, 0xbe, 0xef, 0x0b, 0xc8, 0xfb, 0xbe,
- 0xef, 0x13, 0x68, 0x9a, 0xa6, 0x69, 0x14, 0xe8, 0xfb, 0xbe, 0xef, 0x17,
- 0x08, 0x00, 0x00, 0x00, 0x10, 0xe8, 0xfb, 0xbe, 0xef, 0x17, 0xe8, 0xfb,
- 0xbe, 0xef, 0x17, 0x24, 0x9a, 0xa6, 0x69, 0x24, 0x34, 0x9a, 0xa6, 0x69,
- 0x2c, 0x34, 0x9a, 0xa6, 0x69, 0x28, 0xf4, 0xfb, 0xbe, 0xef, 0x2f, 0x04,
- 0x00, 0x00, 0x00, 0x20, 0xfc, 0xff, 0xff, 0xff, 0x3f, 0x54, 0x55, 0x55,
- 0x55, 0x35, 0xac, 0xaa, 0xaa, 0xaa, 0x2a, 0xf8, 0xff, 0xff, 0xff, 0x1f,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x80, 0x03, 0xf8, 0xff, 0xff, 0xff, 0x0d, 0x04, 0x00, 0x00, 0xf4,
- 0x7f, 0xf8, 0xff, 0xff, 0xff, 0x0e, 0x00, 0x00, 0x00, 0x80, 0x43, 0x00,
- 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00};
-
- #define RGB_FILE "/usr/lib/X11/rgb.txt"
- #define MAX_DB_COLORS 1000
- #define MAX_BUFSIZE 50
- #define MAX_COLORS 256
- /* Numbers of color cells
- */
- #define N_PALETTE 12
- #define N_CUES 11
- Colormap sys_cmap;
-
- float current_AGColors[12][3];
- float initial_AGColors[12][3] = {
- {1.0,0.0,0.0}, /* 1 Red */
- {0.0,0.0,1.0}, /* 2 Blue */
- {0.627,0.125,0.941}, /* 3 Purple */
- {0.275,0.510,0.706}, /* 4 SteelBlue */
- {0.133,0.545,0.133}, /* 5 ForestGreen */
- {0.439,0.500,0.565}, /* 6 SlateGrey */
- {0.690,0.188,0.376}, /* 7 maroon */
- {0.392,0.584,0.930}, /* 8 CornflowerBlue */
- {0.870,0.722,0.530}, /* 9 burlywood */
- {0.914,0.588,0.478}, /* 10 DarkSalmon */
- {0.000,0.808,0.820}, /* 11 DarkTurquoise */
- {1.000,0.937,0.835}, /* 12 PapayaWhip */
- };
-
- /* Read/Write color cells for editing.
- */
- XColor palette_colors [N_PALETTE]; /* view palette */
- XColor editor_color; /* active color in the editor */
- XColor cue_colors [N_CUES]; /* color editor cues */
- /* Initial state of the palette (before editing).
- */
- XColor initial_palette_colors [N_PALETTE];
- /* Entries from the color database.
- */
- char db_color_names [MAX_DB_COLORS] [MAX_BUFSIZE];
- int num_color_names = 0;
- /* Child interfaces.
- */
- extern Widget coloredit;
- extern Widget create_coloredit ();
- extern char *regcmp ();
- extern char *regex ();
- extern void new_init_color ();
- extern void copy_color ();
- extern char* color_string ();
- static void X_to_GL_color ();
- static void setup_colors ();
- static void read_color_db ();
- static void setup_palette ();
- static void activate_color ();
- static void open_color_editor ();
- static void filter_color_names ();
- static void WmCloseCallback ();
- char* GL_to_X_color_string ();
-
- static long CVwin;
-
- /*******************************************************************************
- The definition of the context structure:
- If you create multiple instances of your interface, the context
- structure ensures that your callbacks use the variables for the
- correct instance.
-
- For each swidget in the interface, each argument to the Interface
- function, and each variable in the Instance Specific section of the
- Declarations Editor, there is an entry in the context structure.
- and a #define. The #define makes the variable name refer to the
- corresponding entry in the context structure.
- *******************************************************************************/
-
- typedef struct
- {
- Widget Uxbody_fm;
- Widget Uxmain_pd;
- Widget Uxmain_pd_p2;
- Widget Uxmain_pd_p2_b1;
- Widget Uxmain_pd_p2_b2;
- Widget Uxmain_pd_p2_b3;
- Widget Uxmain_pd_top_b2;
- Widget Uxcolors_box;
- Widget Uxcolors_fm;
- Widget Uxcolor_1;
- Widget Uxcolor_5;
- Widget Uxcolor_7;
- Widget Uxcolor_9;
- Widget Uxcolor_11;
- Widget Uxcolor_2;
- Widget Uxcolor_6;
- Widget Uxcolor_8;
- Widget Uxcolor_10;
- Widget Uxcolor_12;
- Widget Uxcolor_3;
- Widget Uxcolor_4;
- Widget Uxcolor_txt;
- Widget Uxbrowser_box;
- Widget Uxbrowser_fm;
- Widget Uxfilter_lbl;
- Widget Uxfilter_text;
- Widget Uxbrowser_lbl;
- Widget Uxfilter_btn;
- Widget Uxbrowser_sw;
- Widget Uxbrowser_sl;
- Widget Uxok_btn;
- Widget Uxcancel_btn;
- Widget Uxswatch_dsp;
- Widget Uxswatch_fm;
- Widget Uxpalette[N_PALETTE];
- int Uxactive_color;
- } _UxCcolorview;
-
- #define body_fm UxColorviewContext->Uxbody_fm
- #define main_pd UxColorviewContext->Uxmain_pd
- #define main_pd_p2 UxColorviewContext->Uxmain_pd_p2
- #define main_pd_p2_b1 UxColorviewContext->Uxmain_pd_p2_b1
- #define main_pd_p2_b2 UxColorviewContext->Uxmain_pd_p2_b2
- #define main_pd_p2_b3 UxColorviewContext->Uxmain_pd_p2_b3
- #define main_pd_top_b2 UxColorviewContext->Uxmain_pd_top_b2
- #define colors_box UxColorviewContext->Uxcolors_box
- #define colors_fm UxColorviewContext->Uxcolors_fm
- #define color_1 UxColorviewContext->Uxcolor_1
- #define color_5 UxColorviewContext->Uxcolor_5
- #define color_7 UxColorviewContext->Uxcolor_7
- #define color_9 UxColorviewContext->Uxcolor_9
- #define color_11 UxColorviewContext->Uxcolor_11
- #define color_2 UxColorviewContext->Uxcolor_2
- #define color_6 UxColorviewContext->Uxcolor_6
- #define color_8 UxColorviewContext->Uxcolor_8
- #define color_10 UxColorviewContext->Uxcolor_10
- #define color_12 UxColorviewContext->Uxcolor_12
- #define color_3 UxColorviewContext->Uxcolor_3
- #define color_4 UxColorviewContext->Uxcolor_4
- #define color_txt UxColorviewContext->Uxcolor_txt
- #define browser_box UxColorviewContext->Uxbrowser_box
- #define browser_fm UxColorviewContext->Uxbrowser_fm
- #define filter_lbl UxColorviewContext->Uxfilter_lbl
- #define filter_text UxColorviewContext->Uxfilter_text
- #define browser_lbl UxColorviewContext->Uxbrowser_lbl
- #define filter_btn UxColorviewContext->Uxfilter_btn
- #define browser_sw UxColorviewContext->Uxbrowser_sw
- #define browser_sl UxColorviewContext->Uxbrowser_sl
- #define ok_btn UxColorviewContext->Uxok_btn
- #define cancel_btn UxColorviewContext->Uxcancel_btn
- #define swatch_dsp UxColorviewContext->Uxswatch_dsp
- #define swatch_fm UxColorviewContext->Uxswatch_fm
- #define palette UxColorviewContext->Uxpalette
- #define active_color UxColorviewContext->Uxactive_color
-
- static _UxCcolorview *UxColorviewContext;
-
- Widget colorview;
-
- /*******************************************************************************
- The following are translation tables.
- *******************************************************************************/
-
- static char *view_trans = "#override\n\
- <Key>Return:ArmAndActivate()\n";
-
- /*******************************************************************************
- Forward declarations of functions that are defined later in this file.
- *******************************************************************************/
-
- Widget create_colorview();
- void popup_colorview();
- void popdown_colorview();
-
- void setup_colors_widget()
- {
- int numberofcolors;
- struct grptmpltstruct *tmpgrp;
- int j,i, k, n;
- Boolean color_found;
- Widget sw;
-
- numberofcolors = 0;
- tmpgrp = firstgroup;
- while (tmpgrp != NULL && numberofcolors < 12)
- {
- for (j = 0; j < 3; j++)
- current_AGColors[numberofcolors][j] = tmpgrp->covercolor[j];
- numberofcolors++;
- tmpgrp = tmpgrp->nextgrp;
- }
- /* Setup rest of palette for color viewer and create color viewer */
- if (numberofcolors < 12)
- {
- for (i = numberofcolors, n = 0; i <= 12; i++,n++)
- {
- color_found = FALSE;
- for (k = 0; k < numberofcolors; k++)
- {
- if (match_color(current_AGColors[k], initial_AGColors[n]))
- color_found = TRUE;
- }
- if (!color_found)
- {
- for (j = 0; j < 3; j++)
- current_AGColors[i-1][j] = initial_AGColors[n][j];
- }
- }
- }
- sw = create_colorview();
- }
- /*******************************************************************************
- Auxiliary code from the Declarations Editor:
- *******************************************************************************/
-
- /* update_view () - external indication (sent by coloredit)
- * that the active color has been changed.
- * Coloredit has already written the new color to
- * the colorcell; all we need do is update the name.
- */
-
- void update_view ()
- {
- XColor *color;
- double r, g, b;
- char* color_string_buf;
- color_string_buf = (char *)malloc(32);
- /*
- XtVaSetValues( color_txt, XmNvalue,
- color_string (&palette_colors[active_color]), NULL );
- XtVaSetValues( color_txt, XmNcursorPosition,
- strlen(color_string (&palette_colors[active_color])), NULL );
- */
- color = &palette_colors[active_color];
- r = (double) color->red / 65535;
- g = (double) color->green / 65535;
- b = (double) color->blue / 65535;
- sprintf (color_string_buf, "%.2f %.2f %.2f", r, g, b);
- /* printf (" %s\n", color_string_buf); */
- XtVaSetValues( color_txt, XmNvalue, color_string_buf, NULL );
- XtVaSetValues( color_txt, XmNcursorPosition, 14, NULL );
- }
-
- /* Close callback - registered for mwm 'close' button.
- */
-
- static void WmCloseCallback (w, client_data, call_data)
- Widget w;
- caddr_t client_data;
- XmAnyCallbackStruct *call_data;
- {
- popdown_colorview();
- }
-
- /* activate_color () - make the given palette entry the current color.
- */
-
- static void activate_color (n)
- int n;
- {
- Arg args[2];
-
- XtVaSetValues( palette[active_color],
- XmNshadowType, XmSHADOW_ETCHED_IN, NULL );
- XtVaSetValues( palette[n],
- XmNshadowType, XmSHADOW_IN, NULL );
- active_color = n;
- new_init_color (&palette_colors[n]);
- /*
- XtVaSetValues( color_txt, XmNvalue,
- color_string (&palette_colors[n]), NULL );
- XtVaSetValues( color_txt, XmNcursorPosition,
- strlen(color_string (&palette_colors[n])), NULL );
- */
- update_view();
- XtVaSetValues( swatch_dsp,
- XmNbackground, palette_colors[active_color].pixel, NULL );
- }
-
- /* open_color () - pop up the color editor on the current active color.
- */
-
- static void open_color_editor (n)
- int n;
- {
- if (n < 0 || n >= N_PALETTE)
- return;
-
- UxPopupInterface (coloredit, no_grab);
- }
-
-
- /* setup_colors() - allocate and initialize color cells for the editor.
- */
-
- static void setup_colors ()
- {
- Arg arglist[10];
- int i;
- int pixels[N_PALETTE + N_CUES + 1];
-
- sys_cmap = DefaultColormap (UxDisplay,UxScreen);
-
- if (! XAllocColorCells (UxDisplay, sys_cmap, False, NULL, 0,
- pixels,
- N_PALETTE + N_CUES + 1)) {
- fprintf (stderr, "Not enough color cells available for color editor.\n");
- sprintf(msgstring, "Not enough color cells \navailable for color editor.");
- DialogType = 1;
- popup_Message();
- popdown_colorview();
- }
-
- /* Save the initial state of the palette,
- * i.e. the background colors of the palette widgets.
- */
- for (i= 0; i < N_PALETTE; i++) {
- XtSetArg (arglist[0], XmNbackground, &initial_palette_colors[i].pixel);
- XtGetValues (palette[i], arglist,1);
- initial_palette_colors[i].flags = DoRed | DoGreen | DoBlue;
- }
- XQueryColors (UxDisplay, sys_cmap, initial_palette_colors, N_PALETTE);
-
- /* Copy the initial palette into writeable palette color cells.
- */
- for (i = 0; i < N_PALETTE; i++) {
- palette_colors[i].pixel= pixels[i];
- palette_colors[i].flags= DoRed | DoGreen | DoBlue;
- copy_color (&palette_colors[i], &initial_palette_colors[i]);
- }
- XStoreColors (UxDisplay, sys_cmap, palette_colors, N_PALETTE);
-
- /* Bind the writeable palette colors to the palette widgets.
- */
- for (i= 0; i < N_PALETTE; i++) {
- XtSetArg (arglist[0], XmNbackground, palette_colors[i].pixel);
- XtSetValues (palette[i], arglist,1);
- }
-
- XtSetArg (arglist[0], XmNbackground, palette_colors[active_color].pixel);
- XtSetValues (swatch_dsp, arglist, 1);
-
- /* Set up the writeable colors used in coloredit.
- */
- editor_color.pixel = pixels[N_PALETTE+N_CUES];
- editor_color.flags = DoRed | DoGreen | DoBlue;
- for (i=0; i < N_CUES; i++) {
- cue_colors[i].pixel = pixels[N_PALETTE+i];
- cue_colors[i].flags = DoRed | DoBlue | DoGreen;
- }
-
- }
-
- /* read_color_db () - read the color database file.
- */
-
- static void read_color_db ()
- {
- Arg arglist[5];
- FILE *fp;
- int i=0, ret;
- XmString *item_list;
-
- if ((fp = fopen (RGB_FILE, "r")) == NULL) {
- /*
- printf ("Can't open rgb database file: %s\n", RGB_FILE);
- */
- sprintf(msgstring, "Can't open rgb database file:\n%s", RGB_FILE);
- DialogType = 1;
- popup_Message();
- return;
- }
-
- for (i=0; i<MAX_DB_COLORS; i++) {
- ret = fscanf (fp, "%*d%*d%*d ");
- if (ret == EOF)
- break;
- if (ret < 0) {
- /*
- printf ("Couldn't read rgb file. Error %d.\n", ret);
- */
- sprintf(msgstring, "Couldn't read rgb file.\nError %d.", ret);
- DialogType = 1;
- popup_Message();
- break;
- }
- if (fgets (db_color_names[i], MAX_BUFSIZE, fp) == NULL) {
- /*
- printf ("Couldn't read color name.\n");
- */
- sprintf(msgstring, "\nCouldn't read color name.\n");
- DialogType = 1;
- popup_Message();
- break;
- }
- db_color_names[i][strlen (db_color_names[i]) - 1] = '\0';
- }
-
- num_color_names = i;
- filter_color_names ();
-
- fclose (fp);
-
- }
-
- /* filter_color_names () - apply the filter to the color database names,
- * loading the result into the browser list.
- */
- static void filter_color_names ()
- {
- char *value, *reg;
- char regvalue[MAX_BUFSIZE + 2];
- char *nval = regvalue;
- char *oval;
- int numsubkeys=0, i;
- XmString *item_list;
- char *matched;
- Arg arglist[5];
-
- value = XmTextGetString (filter_text);
-
- /* Convert filter string to regular grammar */
- oval = value;
- *nval++ = '^';
- while (*oval) {
- switch (*oval)
- {
- case '.':
- *nval++ = '\\';
- *nval++ = '.';
- break;
- case '?':
- *nval++ = '.';
- break;
- case '*':
- *nval++ = '.';
- *nval++ = '*';
- break;
- default:
- *nval++ = *oval;
- }
- oval++;
- }
- *nval = '\0';
- reg = regcmp (regvalue, 0);
-
- /* Set up item_list to hold sublist of color names */
-
- item_list = (XmString*) XtMalloc (num_color_names * sizeof(XmString));
- for (i=0; i<num_color_names; i++) {
- matched = regex (reg, db_color_names[i]);
- if (matched) {
- item_list[numsubkeys++] = XmStringCreateLtoR (
- db_color_names[i],
- XmSTRING_DEFAULT_CHARSET);
- }
- }
- XtSetArg (arglist[0], XmNitems, item_list);
- XtSetArg (arglist[1], XmNitemCount, numsubkeys);
- XtSetValues (browser_sl, arglist, 2);
-
- for (i=0; i<numsubkeys; i++) {
- XmStringFree(item_list[i]);
- }
- XtFree (item_list);
- }
-
- /* setup_palette () - load the palette array with the actual palette widgets.
- * Must add/delete lines here when changing N_PALETTE.
- */
- static void setup_palette ()
- {
- palette[0] = color_1;
- palette[1] = color_2;
- palette[2] = color_3;
- palette[3] = color_4;
- palette[4] = color_5;
- palette[5] = color_6;
- palette[6] = color_7;
- palette[7] = color_8;
- palette[8] = color_9;
- palette[9] = color_10;
- palette[10] = color_11;
- palette[11] = color_12;
- }
-
- /*******************************************************************************
- The following are callback functions.
- *******************************************************************************/
-
- static void destroyCB_colorview( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- popdown_colorview();
- }
- UxColorviewContext = UxSaveCtx;
- }
-
- static void activateCB_main_pd_p2_b2( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- int i,j;
- for (i = 0; i < N_PALETTE; i++) {
- copy_color (&palette_colors[i], &initial_palette_colors[i]);
- X_to_GL_color (&palette_colors[i], current_AGColors[i]);
- /*
- for (j=0; j<3; j++)
- current_AGColors[i][j] = initial_AGColors[i][j];
- printf("R = %f G = %f B = %f\n",
- current_AGColors[i][0], current_AGColors[i][1], current_AGColors[i][2]);
- */
- }
- XStoreColors (UxDisplay, sys_cmap, palette_colors, N_PALETTE);
- update_view();
- }
- UxColorviewContext = UxSaveCtx;
- }
-
- static void activateCB_main_pd_p2_b3( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- int i,j;
- for (i = 0; i < N_PALETTE; i++) {
- copy_color (&palette_colors[i], &initial_palette_colors[i]);
- /*
- for (j=0; j<3; j++)
- current_AGColors[i][j] = initial_AGColors[i][j];
- printf("R = %f G = %f B = %f\n",
- current_AGColors[i][0], current_AGColors[i][1], current_AGColors[i][2]);
- */
- }
- XStoreColors (UxDisplay, sys_cmap, palette_colors, N_PALETTE);
- update_view();
- }
- UxColorviewContext = UxSaveCtx;
- }
-
-
- static void activateCB_main_pd_p2_b1( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- open_color_editor (active_color);
- }
- UxColorviewContext = UxSaveCtx;
- }
-
- static void activateCB_color_1( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- activate_color (0);
- }
- UxColorviewContext = UxSaveCtx;
- }
-
- static void activateCB_color_5( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- activate_color (4);
- }
- UxColorviewContext = UxSaveCtx;
- }
-
- static void activateCB_color_7( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- activate_color (6);
- }
- UxColorviewContext = UxSaveCtx;
- }
-
- static void activateCB_color_9( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- activate_color (8);
- }
- UxColorviewContext = UxSaveCtx;
- }
-
- static void activateCB_color_11( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- activate_color (10);
- }
- UxColorviewContext = UxSaveCtx;
- }
-
- static void activateCB_color_2( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- activate_color (1);
- }
- UxColorviewContext = UxSaveCtx;
- }
-
- static void activateCB_color_6( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- activate_color (5);
- }
- UxColorviewContext = UxSaveCtx;
- }
-
- static void activateCB_color_8( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- activate_color (7);
- }
- UxColorviewContext = UxSaveCtx;
- }
-
- static void activateCB_color_10( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- activate_color (9);
- }
- UxColorviewContext = UxSaveCtx;
- }
-
- static void activateCB_color_12( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- activate_color (11);
- }
- UxColorviewContext = UxSaveCtx;
- }
-
- static void activateCB_color_3( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- activate_color (2);
- }
- UxColorviewContext = UxSaveCtx;
- }
-
- static void activateCB_color_4( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- activate_color (3);
- }
- UxColorviewContext = UxSaveCtx;
- }
-
- static void activateCB_color_txt( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- char *newname;
- char *color_string;
- Boolean GLParseColor();
-
- newname = (char *)XmTextFieldGetString (UxWidget);
- color_string = (char *)malloc( sizeof(char) * 32);
- color_string[0] = '\0';
- if (!GLParseColor (newname, color_string)) {
- sprintf(msgstring, "problem parsing GL color %s\n", newname);
- DialogType = 1;
- popup_Message();
- return;
- }
- if (!XParseColor (UxDisplay, sys_cmap, color_string, &palette_colors[active_color])) {
- sprintf(msgstring, "problem parsing color %s\n", color_string);
- DialogType = 1;
- popup_Message();
- return;
- }
- XStoreColor (UxDisplay,sys_cmap,&palette_colors[active_color]);
- }
- UxColorviewContext = UxSaveCtx;
- }
-
- static void losingFocusCB_filter_text( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- XtVaSetValues( filter_btn, XmNshowAsDefault, 0, NULL );
- }
- UxColorviewContext = UxSaveCtx;
- }
-
- static void focusCB_filter_text( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- XtVaSetValues( filter_btn, XmNshowAsDefault, 1, NULL );
- }
- UxColorviewContext = UxSaveCtx;
- }
-
- static void activateCB_filter_text( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- XtCallCallbacks (filter_btn, XmNactivateCallback, NULL);
- }
- UxColorviewContext = UxSaveCtx;
- }
-
- static void activateCB_filter_btn( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- filter_color_names();
- }
- UxColorviewContext = UxSaveCtx;
- }
-
- static void activateCB_ok_btn( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- XColor color;
- double rval, gval, bval;
- int i;
-
- color = palette_colors[active_color];
- /* printf("R = %d G = %d B = %d\n",color.red,color.green,color.blue); */
- rval = (double) color.red * 255 / 65535;
- gval = (double) color.green * 255 / 65535;
- bval = (double) color.blue * 255 / 65535;
- AGColor[0] = (float) rval / 255.0;
- AGColor[1] = (float) gval / 255.0;
- AGColor[2] = (float) bval / 255.0;
- /* printf("R = %f G = %f B = %f\n",AGColor[0],AGColor[1],AGColor[2]); */
- for (i=0; i<N_PALETTE; i++)
- X_to_GL_color (&palette_colors[i], current_AGColors[i]);
- popdown_colorview();
- }
-
- UxColorviewContext = UxSaveCtx;
- }
-
- static void activateCB_cancel_btn( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- int i;
- for (i=0; i<N_PALETTE; i++)
- X_to_GL_color (&palette_colors[i], current_AGColors[i]);
- popdown_colorview();
- }
-
- UxColorviewContext = UxSaveCtx;
- }
-
- static void singleSelectionCB_browser_sl( UxWidget, UxClientData, UxCallbackArg )
- Widget UxWidget;
- XtPointer UxClientData, UxCallbackArg;
- {
- _UxCcolorview *UxSaveCtx, *UxContext;
-
- UxSaveCtx = UxColorviewContext;
- UxColorviewContext = UxContext =
- (_UxCcolorview *) UxGetContext( UxWidget );
- {
- char *newname;
- XmListCallbackStruct *cbs;
- cbs = (XmListCallbackStruct *)UxCallbackArg;
- XmStringGetLtoR (cbs->item, XmSTRING_DEFAULT_CHARSET, &newname);
- if (!XParseColor (UxDisplay, sys_cmap, newname, &palette_colors[active_color])) {
- /*
- printf ("problem parsing color %s\n", newname);
- */
- sprintf(msgstring, "problem parsing color %s\n", newname);
- DialogType = 1;
- popup_Message();
- return;
- }
- XStoreColor (UxDisplay,sys_cmap,&palette_colors[active_color]);
- XtVaSetValues( color_txt, XmNvalue, newname, NULL );
- XtVaSetValues( color_txt, XmNcursorPosition, strlen(newname), NULL );
- XtVaSetValues( palette[active_color],
- XmNbackground, palette_colors[active_color].pixel, NULL );
- XtVaSetValues( palette[active_color],
- XmNshadowType, XmSHADOW_IN, NULL );
- XtVaSetValues( swatch_dsp,
- XmNbackground, palette_colors[active_color].pixel, NULL );
- }
- UxColorviewContext = UxSaveCtx;
- }
-
-
- /*******************************************************************************
- The 'build_' function creates all the widgets
- using the resource values specified in the Property Editor.
- *******************************************************************************/
-
- static Widget _Uxbuild_colorview()
- {
- Widget main_pd_p2_shell;
- Arg wargs[10];
- int n;
-
- n = 0;
- XtSetArg(wargs[n], XmNheight, 439); n++;
- printf("XmNheight, 439 \n");
- XtSetArg(wargs[n], XmNwidth, 316); n++;
- printf("XmNwidth, 316) \n");
- XtSetArg(wargs[n], XmNminHeight, 300); n++;
- XtSetArg(wargs[n], XmNminWidth, 200); n++;
- XtSetArg(wargs[n], XmNtitle, "Color Viewer"); n++;
- XtSetArg(wargs[n], XmNx, 300); n++;
- XtSetArg(wargs[n], XmNy, 200); n++;
-
- colorview = XtCreatePopupShell( "colorview",
- topLevelShellWidgetClass, CreateGroup,
- wargs, n);
- printf(" after XtCreatePopupShell \n");
-
- UxPutContext( colorview, (char *) UxColorviewContext );
- printf(" after UxPutContext \n");
-
- body_fm = XtVaCreateManagedWidget( "body_fm",
- xmFormWidgetClass, colorview,
- XmNheight, 570,
- XmNwidth, 320,
- XmNy, 0,
- XmNx, 20,
- NULL );
-
- UxPutContext( body_fm, (char *) UxColorviewContext );
-
- main_pd = XtVaCreateManagedWidget( "main_pd",
- xmRowColumnWidgetClass, body_fm,
- XmNtopOffset, 0,
- XmNtopAttachment, XmATTACH_FORM,
- XmNrightOffset, 0,
- XmNrightAttachment, XmATTACH_FORM,
- XmNleftOffset, 0,
- XmNleftAttachment, XmATTACH_FORM,
- XmNbottomAttachment, XmATTACH_NONE,
- XmNrowColumnType, XmMENU_BAR,
- XmNborderWidth, 0,
- XmNheight, 28,
- XmNy, 30,
- XmNx, 140,
- NULL );
-
- UxPutContext( main_pd, (char *) UxColorviewContext );
-
- main_pd_p2_shell = XtVaCreatePopupShell ("main_pd_p2_shell",
- xmMenuShellWidgetClass, main_pd,
- XmNwidth, 1,
- XmNheight, 1,
- XmNallowShellResize, TRUE,
- XmNoverrideRedirect, TRUE,
- NULL );
-
- main_pd_p2 = XtVaCreateWidget( "main_pd_p2",
- xmRowColumnWidgetClass, main_pd_p2_shell,
- XmNrowColumnType, XmMENU_PULLDOWN,
- NULL );
-
- UxPutContext( main_pd_p2, (char *) UxColorviewContext );
-
- main_pd_p2_b1 = XtVaCreateManagedWidget( "main_pd_p2_b1",
- xmPushButtonGadgetClass, main_pd_p2,
- RES_CONVERT( XmNfontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
- RES_CONVERT( XmNlabelString, "Edit Color ..." ),
- /*
- RES_CONVERT( XmNbackground, "#BBBBBB" ),
- */
- NULL );
-
- UxPutContext( main_pd_p2_b1, (char *) UxColorviewContext );
-
- /*
- main_pd_p2_b2 = XtVaCreateManagedWidget( "main_pd_p2_b2",
- xmPushButtonGadgetClass, main_pd_p2,
- RES_CONVERT( XmNfontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
- RES_CONVERT( XmNlabelString, "Reset" ),
- RES_CONVERT( XmNbackground, "#BBBBBB" ),
- NULL );
-
- UxPutContext( main_pd_p2_b2, (char *) UxColorviewContext );
-
- main_pd_p2_b3 = XtVaCreateManagedWidget( "main_pd_p2_b3",
- xmPushButtonGadgetClass, main_pd_p2,
- RES_CONVERT( XmNfontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
- RES_CONVERT( XmNlabelString, "Demobook Colors" ),
- RES_CONVERT( XmNbackground, "#BBBBBB" ),
- NULL );
-
- UxPutContext( main_pd_p2_b3, (char *) UxColorviewContext );
- */
-
- main_pd_top_b2 = XtVaCreateManagedWidget( "main_pd_top_b2",
- xmCascadeButtonWidgetClass, main_pd,
- XmNsubMenuId, main_pd_p2,
- RES_CONVERT( XmNfontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
- RES_CONVERT( XmNlabelString, "Edit" ),
- /*
- RES_CONVERT( XmNbackground, "#BBBBBB" ),
- */
- NULL );
-
- UxPutContext( main_pd_top_b2, (char *) UxColorviewContext );
-
- colors_box = XtVaCreateManagedWidget( "colors_box",
- xmFrameWidgetClass, body_fm,
- XmNtopWidget, main_pd,
- XmNtopOffset, 0,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNrightOffset, 0,
- XmNrightAttachment, XmATTACH_FORM,
- XmNleftOffset, 0,
- XmNleftAttachment, XmATTACH_FORM,
- XmNshadowType, XmSHADOW_OUT,
- XmNmarginWidth, 8,
- XmNmarginHeight, 8,
- /*
- RES_CONVERT( XmNbackground, "#BBBBBB" ),
- */
- XmNshadowThickness, 5,
- XmNwidth, 320,
- XmNy, 34,
- XmNx, 0,
- NULL );
-
- UxPutContext( colors_box, (char *) UxColorviewContext );
-
- colors_fm = XtVaCreateManagedWidget( "colors_fm",
- xmFormWidgetClass, colors_box,
- RES_CONVERT( XmNtextFontList, "-Adobe-Courier-Bold-R-Normal--14-100-100-100-M-90-ISO8859-1" ),
- RES_CONVERT( XmNlabelFontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
- RES_CONVERT( XmNbuttonFontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
- XmNy, 0,
- XmNx, 0,
- XmNheight, 91,
- XmNwidth, 300,
- XmNautoUnmanage, FALSE,
- XmNallowOverlap, FALSE,
- XmNborderWidth, 0,
- /*
- RES_CONVERT( XmNbackground, "#BBBBBB" ),
- */
- NULL );
-
- UxPutContext( colors_fm, (char *) UxColorviewContext );
-
- color_1 = XtVaCreateManagedWidget( "color_1",
- xmDrawnButtonWidgetClass, colors_fm,
- XmNtopOffset, 0,
- XmNtopAttachment, XmATTACH_FORM,
- XmNrightPosition, 16,
- XmNrightAttachment, XmATTACH_POSITION,
- XmNleftPosition, 0,
- XmNleftAttachment, XmATTACH_POSITION,
- XmNshadowType, XmSHADOW_ETCHED_IN,
- XmNshadowThickness, 3,
- XmNheight, 24,
- RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[0])),
- NULL );
-
- UxPutContext( color_1, (char *) UxColorviewContext );
-
- color_3 = XtVaCreateManagedWidget( "color_3",
- xmDrawnButtonWidgetClass, colors_fm,
- XmNtopOffset, 0,
- XmNtopAttachment, XmATTACH_FORM,
- XmNrightPosition, 33,
- XmNrightAttachment, XmATTACH_POSITION,
- XmNleftPosition, 16,
- XmNleftAttachment, XmATTACH_POSITION,
- XmNshadowType, XmSHADOW_ETCHED_IN,
- XmNshadowThickness, 3,
- XmNheight, 24,
- RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[2])),
- NULL );
-
- UxPutContext( color_3, (char *) UxColorviewContext );
-
- color_5 = XtVaCreateManagedWidget( "color_5",
- xmDrawnButtonWidgetClass, colors_fm,
- XmNtopOffset, 0,
- XmNtopAttachment, XmATTACH_FORM,
- XmNrightPosition, 50,
- XmNrightAttachment, XmATTACH_POSITION,
- XmNleftPosition, 33,
- XmNleftAttachment, XmATTACH_POSITION,
- XmNshadowType, XmSHADOW_ETCHED_IN,
- XmNshadowThickness, 3,
- XmNheight, 24,
- RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[4])),
- NULL );
-
- UxPutContext( color_5, (char *) UxColorviewContext );
-
- color_7 = XtVaCreateManagedWidget( "color_7",
- xmDrawnButtonWidgetClass, colors_fm,
- XmNtopPosition, 0,
- XmNtopAttachment, XmATTACH_POSITION,
- XmNrightPosition, 67,
- XmNrightAttachment, XmATTACH_POSITION,
- XmNleftPosition, 50,
- XmNleftAttachment, XmATTACH_POSITION,
- XmNshadowType, XmSHADOW_ETCHED_IN,
- XmNshadowThickness, 3,
- XmNheight, 24,
- RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[6])),
- NULL );
-
- UxPutContext( color_7, (char *) UxColorviewContext );
-
- color_9 = XtVaCreateManagedWidget( "color_9",
- xmDrawnButtonWidgetClass, colors_fm,
- XmNtopOffset, 0,
- XmNtopAttachment, XmATTACH_FORM,
- XmNrightPosition, 84,
- XmNrightAttachment, XmATTACH_POSITION,
- XmNleftPosition, 67,
- XmNleftAttachment, XmATTACH_POSITION,
- XmNshadowType, XmSHADOW_ETCHED_IN,
- XmNshadowThickness, 3,
- XmNheight, 24,
- RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[8])),
- NULL );
-
- UxPutContext( color_9, (char *) UxColorviewContext );
-
- color_11 = XtVaCreateManagedWidget( "color_11",
- xmDrawnButtonWidgetClass, colors_fm,
- XmNtopPosition, 0,
- XmNtopAttachment, XmATTACH_POSITION,
- XmNrightPosition, 100,
- XmNrightAttachment, XmATTACH_POSITION,
- XmNleftPosition, 84,
- XmNleftAttachment, XmATTACH_POSITION,
- XmNshadowType, XmSHADOW_ETCHED_IN,
- XmNshadowThickness, 3,
- XmNheight, 24,
- RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[10])),
- NULL );
-
- UxPutContext( color_11, (char *) UxColorviewContext );
-
- color_2 = XtVaCreateManagedWidget( "color_2",
- xmDrawnButtonWidgetClass, colors_fm,
- XmNtopWidget, color_1,
- XmNtopPosition, 30,
- XmNtopOffset, 0,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNrightPosition, 16,
- XmNrightAttachment, XmATTACH_POSITION,
- XmNleftPosition, 0,
- XmNleftAttachment, XmATTACH_POSITION,
- XmNshadowType, XmSHADOW_ETCHED_IN,
- XmNshadowThickness, 3,
- XmNheight, 24,
- XmNy, 30,
- XmNx, 0,
- RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[1])),
- NULL );
-
- UxPutContext( color_2, (char *) UxColorviewContext );
-
- color_4 = XtVaCreateManagedWidget( "color_4",
- xmDrawnButtonWidgetClass, colors_fm,
- XmNtopWidget, color_3,
- XmNtopOffset, 0,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNrightPosition, 33,
- XmNrightAttachment, XmATTACH_POSITION,
- XmNleftPosition, 16,
- XmNleftAttachment, XmATTACH_POSITION,
- XmNshadowType, XmSHADOW_ETCHED_IN,
- XmNshadowThickness, 3,
- XmNheight, 24,
- XmNwidth, 51,
- XmNy, 30,
- XmNx, 48,
- RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[3])),
- NULL );
-
- UxPutContext( color_4, (char *) UxColorviewContext );
-
- color_6 = XtVaCreateManagedWidget( "color_6",
- xmDrawnButtonWidgetClass, colors_fm,
- XmNtopWidget, color_5,
- XmNtopOffset, 0,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNrightPosition, 50,
- XmNrightAttachment, XmATTACH_POSITION,
- XmNleftPosition, 33,
- XmNleftAttachment, XmATTACH_POSITION,
- XmNshadowType, XmSHADOW_ETCHED_IN,
- XmNshadowThickness, 3,
- XmNheight, 24,
- RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[5])),
- NULL );
-
- UxPutContext( color_6, (char *) UxColorviewContext );
-
- color_8 = XtVaCreateManagedWidget( "color_8",
- xmDrawnButtonWidgetClass, colors_fm,
- XmNtopWidget, color_7,
- XmNtopOffset, 0,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNrightPosition, 67,
- XmNrightAttachment, XmATTACH_POSITION,
- XmNleftPosition, 50,
- XmNleftAttachment, XmATTACH_POSITION,
- XmNshadowType, XmSHADOW_ETCHED_IN,
- XmNshadowThickness, 3,
- XmNheight, 24,
- RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[7])),
- NULL );
-
- UxPutContext( color_8, (char *) UxColorviewContext );
-
- color_10 = XtVaCreateManagedWidget( "color_10",
- xmDrawnButtonWidgetClass, colors_fm,
- XmNtopWidget, color_9,
- XmNtopPosition, 0,
- XmNtopOffset, 0,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNrightPosition, 84,
- XmNrightAttachment, XmATTACH_POSITION,
- XmNleftPosition, 67,
- XmNleftAttachment, XmATTACH_POSITION,
- XmNshadowType, XmSHADOW_ETCHED_IN,
- XmNshadowThickness, 3,
- XmNheight, 24,
- RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[9])),
- NULL );
-
- UxPutContext( color_10, (char *) UxColorviewContext );
-
- color_12 = XtVaCreateManagedWidget( "color_12",
- xmDrawnButtonWidgetClass, colors_fm,
- XmNtopWidget, color_11,
- XmNtopPosition, 0,
- XmNtopOffset, 0,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNrightPosition, 100,
- XmNrightAttachment, XmATTACH_POSITION,
- XmNleftPosition, 84,
- XmNleftAttachment, XmATTACH_POSITION,
- XmNshadowType, XmSHADOW_ETCHED_IN,
- XmNshadowThickness, 3,
- XmNheight, 24,
- RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[11])),
- NULL );
-
- UxPutContext( color_12, (char *) UxColorviewContext );
-
- swatch_fm = XtVaCreateManagedWidget( "swatch_fm",
- xmFormWidgetClass, colors_fm,
- XmNtopWidget, color_2,
- XmNtopOffset, 5,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNrightPosition, 50,
- XmNrightOffset, 2,
- XmNrightAttachment, XmATTACH_POSITION,
- XmNleftOffset, 0,
- XmNleftAttachment, XmATTACH_FORM,
- XmNbottomOffset, 0,
- XmNbottomAttachment, XmATTACH_FORM,
- RES_CONVERT( XmNbackground, "#BBBBBB" ),
- XmNshadowType, XmSHADOW_IN,
- XmNshadowThickness, 3,
- NULL );
-
- UxPutContext( swatch_fm, (char *) UxColorviewContext );
-
- swatch_dsp = XtVaCreateManagedWidget( "swatch_dsp",
- xmDrawingAreaWidgetClass, swatch_fm,
- /*
- XmNtopWidget, color_2,
- XmNtopOffset, 5,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNrightPosition, 50,
- XmNrightAttachment, XmATTACH_POSITION,
- XmNleftPosition, 0,
- XmNleftAttachment, XmATTACH_POSITION,
- */
- XmNtopOffset, 3,
- XmNtopAttachment, XmATTACH_FORM,
- XmNrightOffset, 3,
- XmNrightAttachment, XmATTACH_FORM,
- XmNleftOffset, 3,
- XmNleftAttachment, XmATTACH_FORM,
- XmNbottomOffset, 3,
- XmNbottomAttachment, XmATTACH_FORM,
- XmNresizePolicy, XmRESIZE_NONE,
- XmNheight, 33,
- XmNwidth, 10,
- RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[0]) ),
- NULL );
-
- UxPutContext( swatch_dsp, (char *) UxColorviewContext );
-
- color_txt = XtVaCreateManagedWidget( "color_txt",
- xmTextFieldWidgetClass, colors_fm,
- /*
- RES_CONVERT( XmNbackground, "#7777BB" ),
- */
- RES_CONVERT( XmNfontList, "-Adobe-Courier-Bold-R-Normal--14-100-100-100-M-90-ISO8859-1" ),
- /* XmNeditable, FALSE, */
- XmNleftWidget, swatch_fm,
- XmNleftOffset, 0,
- XmNleftAttachment, XmATTACH_WIDGET,
- XmNtopWidget, color_8,
- XmNtopOffset, 6,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNrightOffset, 0,
- XmNrightAttachment, XmATTACH_FORM,
- /*
- XmNheight, 35,
- XmNwidth, 155,
- XmNy, 50,
- XmNx, 150,
- */
- NULL );
-
- UxPutContext( color_txt, (char *) UxColorviewContext );
-
- browser_box = XtVaCreateManagedWidget( "browser_box",
- xmFrameWidgetClass, body_fm,
- XmNtopWidget, colors_box,
- XmNtopOffset, 0,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNrightOffset, 0,
- XmNrightAttachment, XmATTACH_FORM,
- XmNleftOffset, 0,
- XmNleftAttachment, XmATTACH_FORM,
- XmNbottomOffset, 0,
- XmNbottomAttachment, XmATTACH_FORM,
- XmNshadowType, XmSHADOW_OUT,
- /*
- RES_CONVERT( XmNbackground, "#BBBBBB" ),
- XmNshadowThickness, 5,
- */
- XmNheight, 360,
- XmNwidth, 316,
- XmNy, 80,
- XmNx, 0,
- NULL );
-
- UxPutContext( browser_box, (char *) UxColorviewContext );
-
- browser_fm = XtVaCreateManagedWidget( "browser_fm",
- xmFormWidgetClass, browser_box,
- XmNverticalSpacing, 5,
- XmNhorizontalSpacing, 5,
- XmNborderWidth, 0,
- /*
- RES_CONVERT( XmNbackground, "#BBBBBB" ),
- */
- XmNheight, 360,
- XmNwidth, 310,
- XmNy, 0,
- XmNx, 0,
- NULL );
-
- UxPutContext( browser_fm, (char *) UxColorviewContext );
-
- filter_lbl = XtVaCreateManagedWidget( "filter_lbl",
- xmLabelGadgetClass, browser_fm,
- XmNtopAttachment, XmATTACH_FORM,
- XmNleftAttachment, XmATTACH_FORM,
- RES_CONVERT( XmNfontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
- RES_CONVERT( XmNlabelString, "Name Filter:" ),
- XmNalignment, XmALIGNMENT_BEGINNING,
- /*
- RES_CONVERT( XmNbackground, "#BBBBBB" ),
- */
- NULL );
-
- UxPutContext( filter_lbl, (char *) UxColorviewContext );
-
- filter_text = XtVaCreateManagedWidget( "filter_text",
- xmTextWidgetClass, browser_fm,
- /*
- RES_CONVERT( XmNbackground, "#7777BB" ),
- */
- RES_CONVERT( XmNtextFontList, "-Adobe-Courier-Bold-R-Normal--14-100-100-100-M-90-ISO8859-1" ),
- XmNtopWidget, filter_lbl,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNrightAttachment, XmATTACH_FORM,
- XmNleftAttachment, XmATTACH_FORM,
- XmNvalue, "[A-Z]*",
- NULL );
-
- UxPutContext( filter_text, (char *) UxColorviewContext );
-
- browser_lbl = XtVaCreateManagedWidget( "browser_lbl",
- xmLabelGadgetClass, browser_fm,
- XmNtopWidget, filter_text,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNleftAttachment, XmATTACH_FORM,
- RES_CONVERT( XmNfontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
- RES_CONVERT( XmNlabelString, "Color Database:" ),
- /*
- RES_CONVERT( XmNbackground, "#BBBBBB" ),
- */
- NULL );
-
- UxPutContext( browser_lbl, (char *) UxColorviewContext );
-
- ok_btn = XtVaCreateManagedWidget( "ok_btn",
- xmPushButtonWidgetClass, browser_fm,
- XmNmarginRight, 7,
- XmNmarginLeft, 7,
- XmNrightPosition, 30,
- XmNrightAttachment, XmATTACH_POSITION,
- XmNleftPosition, 5,
- XmNleftAttachment, XmATTACH_POSITION,
- XmNbottomOffset, 2,
- XmNbottomAttachment, XmATTACH_FORM,
- XmNrecomputeSize, FALSE,
- RES_CONVERT( XmNfontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
- RES_CONVERT( XmNlabelString, "Done" ),
- /*
- RES_CONVERT( XmNbackground, "#BBBBBB" ),
- */
- XmNheight, 26,
- XmNwidth, 92,
- NULL );
-
- UxPutContext( ok_btn, (char *) UxColorviewContext );
-
- filter_btn = XtVaCreateManagedWidget( "filter_btn",
- xmPushButtonWidgetClass, browser_fm,
- XmNmarginRight, 7,
- XmNmarginLeft, 7,
- XmNrightPosition, 62,
- XmNrightAttachment, XmATTACH_POSITION,
- XmNleftPosition, 37,
- XmNleftAttachment, XmATTACH_POSITION,
- XmNbottomOffset, 2,
- XmNbottomAttachment, XmATTACH_FORM,
- XmNrecomputeSize, FALSE,
- RES_CONVERT( XmNfontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
- RES_CONVERT( XmNlabelString, "Filter" ),
- /*
- RES_CONVERT( XmNbackground, "#BBBBBB" ),
- */
- RES_CONVERT( XmNaccelerators, view_trans ),
- XmNheight, 26,
- XmNwidth, 74,
- NULL );
-
- UxPutContext( filter_btn, (char *) UxColorviewContext );
-
- cancel_btn = XtVaCreateManagedWidget( "cancel_btn",
- xmPushButtonWidgetClass, browser_fm,
- XmNmarginRight, 7,
- XmNmarginLeft, 7,
- XmNrightPosition, 95,
- XmNrightAttachment, XmATTACH_POSITION,
- XmNleftPosition, 70,
- XmNleftAttachment, XmATTACH_POSITION,
- XmNbottomOffset, 2,
- XmNbottomAttachment, XmATTACH_FORM,
- XmNrecomputeSize, FALSE,
- RES_CONVERT( XmNfontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
- RES_CONVERT( XmNlabelString, "Cancel" ),
- /*
- RES_CONVERT( XmNbackground, "#BBBBBB" ),
- */
- XmNheight, 26,
- XmNwidth, 74,
- NULL );
-
- UxPutContext( cancel_btn, (char *) UxColorviewContext );
-
- browser_sw = XtVaCreateManagedWidget( "browser_sw",
- xmScrolledWindowWidgetClass, browser_fm,
- RES_CONVERT( XmNbackground, "#7777BB" ),
- XmNtopWidget, browser_lbl,
- XmNtopAttachment, XmATTACH_WIDGET,
- XmNrightAttachment, XmATTACH_FORM,
- XmNleftAttachment, XmATTACH_FORM,
- XmNbottomOffset, 40,
- XmNbottomAttachment, XmATTACH_FORM,
- XmNscrollingPolicy, XmAPPLICATION_DEFINED,
- XmNscrollBarDisplayPolicy, XmSTATIC,
- XmNborderWidth, 0,
- NULL );
-
- UxPutContext( browser_sw, (char *) UxColorviewContext );
-
- browser_sl = XtVaCreateManagedWidget( "browser_sl",
- xmListWidgetClass, browser_sw,
- /*
- RES_CONVERT( XmNbackground, "#7777BB" ),
- */
- XmNselectionPolicy, XmSINGLE_SELECT,
- XmNlistSpacing, 2,
- XmNvisibleItemCount, 6,
- XmNlistMarginHeight, 2,
- RES_CONVERT( XmNfontList, "-Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO8859-1" ),
- XmNheight, 180,
- XmNwidth, 284,
- XmNy, 0,
- XmNx, 0,
- NULL );
-
- UxPutContext( browser_sl, (char *) UxColorviewContext );
-
- XtAddCallback( colorview, XmNdestroyCallback,
- UxFreeClientDataCB,
- (XtPointer) UxColorviewContext );
-
- XtAddCallback( colorview, XmNdestroyCallback,
- destroyCB_colorview,
- (XtPointer) UxColorviewContext );
-
- XtAddCallback( main_pd_p2_b1, XmNactivateCallback,
- activateCB_main_pd_p2_b1,
- (XtPointer) UxColorviewContext );
-
- /*
- XtAddCallback( main_pd_p2_b2, XmNactivateCallback,
- activateCB_main_pd_p2_b2,
- (XtPointer) UxColorviewContext );
-
- XtAddCallback( main_pd_p2_b3, XmNactivateCallback,
- activateCB_main_pd_p2_b3,
- (XtPointer) UxColorviewContext );
- */
-
- XtAddCallback( color_1, XmNactivateCallback,
- activateCB_color_1,
- (XtPointer) UxColorviewContext );
-
- XtAddCallback( color_5, XmNactivateCallback,
- activateCB_color_5,
- (XtPointer) UxColorviewContext );
-
- XtAddCallback( color_7, XmNactivateCallback,
- activateCB_color_7,
- (XtPointer) UxColorviewContext );
-
- XtAddCallback( color_9, XmNactivateCallback,
- activateCB_color_9,
- (XtPointer) UxColorviewContext );
-
- XtAddCallback( color_11, XmNactivateCallback,
- activateCB_color_11,
- (XtPointer) UxColorviewContext );
-
- XtAddCallback( color_2, XmNactivateCallback,
- activateCB_color_2,
- (XtPointer) UxColorviewContext );
-
- XtAddCallback( color_6, XmNactivateCallback,
- activateCB_color_6,
- (XtPointer) UxColorviewContext );
-
- XtAddCallback( color_8, XmNactivateCallback,
- activateCB_color_8,
- (XtPointer) UxColorviewContext );
-
- XtAddCallback( color_10, XmNactivateCallback,
- activateCB_color_10,
- (XtPointer) UxColorviewContext );
-
- XtAddCallback( color_12, XmNactivateCallback,
- activateCB_color_12,
- (XtPointer) UxColorviewContext );
-
- XtAddCallback( color_3, XmNactivateCallback,
- activateCB_color_3,
- (XtPointer) UxColorviewContext );
-
- XtAddCallback( color_4, XmNactivateCallback,
- activateCB_color_4,
- (XtPointer) UxColorviewContext );
-
- XtAddCallback( color_txt, XmNactivateCallback,
- activateCB_color_txt,
- (XtPointer) UxColorviewContext );
-
- XtVaSetValues( browser_fm, XmNdefaultButton, ok_btn, NULL );
-
- XtAddCallback( filter_text, XmNlosingFocusCallback,
- losingFocusCB_filter_text,
- (XtPointer) UxColorviewContext );
- XtAddCallback( filter_text, XmNfocusCallback,
- focusCB_filter_text,
- (XtPointer) UxColorviewContext );
- XtAddCallback( filter_text, XmNactivateCallback,
- activateCB_filter_text,
- (XtPointer) UxColorviewContext );
-
- XtAddCallback( filter_btn, XmNactivateCallback,
- activateCB_filter_btn,
- (XtPointer) UxColorviewContext );
-
- XtAddCallback( browser_sl, XmNsingleSelectionCallback,
- singleSelectionCB_browser_sl,
- (XtPointer) UxColorviewContext );
-
- XtAddCallback( ok_btn, XmNactivateCallback,
- activateCB_ok_btn,
- (XtPointer) UxColorviewContext );
-
- XtAddCallback( cancel_btn, XmNactivateCallback,
- activateCB_cancel_btn,
- (XtPointer) UxColorviewContext );
-
-
- return ( colorview );
- }
-
-
- /*******************************************************************************
- The following function includes the code that was entered
- in the 'Initial Code' and 'Final Code' sections of the
- Declarations Editor. This function is called from the
- 'Interface function' below.
- *******************************************************************************/
-
- static Widget _Ux_create_colorview()
- {
- Widget rtrn;
- _UxCcolorview *UxContext;
-
- UxColorviewContext = UxContext =
- (_UxCcolorview *) XtMalloc( sizeof(_UxCcolorview) );
-
- {
- active_color = 0;
- rtrn = _Uxbuild_colorview();
-
- setup_palette (); /* make table of palette boxes */
- setup_colors (); /* allocate read/write colorcells */
- create_coloredit (colorview, &palette_colors[0], &editor_color);
- {
- Atom a;
- a = XmInternAtom (UxDisplay, "WM_DELETE_WINDOW", FALSE);
- XmAddWMProtocols (colorview, &a, 1);
- XmAddWMProtocolCallback (colorview, a, WmCloseCallback, 0);
- }
- XtInstallAccelerators (filter_text, filter_btn);
- read_color_db ();
- /*
- activate_color (0);
- SetWMhints( colorview );
- UxPopupInterface (colorview, no_grab);
- return (colorview);
- */
- XtRealizeWidget( colorview );
-
- SetWMhints( colorview );
-
- return (rtrn);
- }
- }
-
- /*******************************************************************************
- The following is the 'Interface function' which is the
- external entry point for creating this interface.
- This function should be called from your application or from
- a callback function.
- *******************************************************************************/
-
- Widget create_colorview()
- {
- Widget _Uxrtrn;
-
- _Uxrtrn = _Ux_create_colorview();
-
- return ( _Uxrtrn );
- }
-
- void popup_colorview()
- {
- Boolean color_found;
- char *xcolorstring;
- int i, isav;
-
- if (CVwin <= 0) {
- /*
- sprintf(msgstring, "\nLoading in Color Viewer ...\n");
- UxPopupInterface(create_Working(), no_grab);
- handleMotifInterfaceEvents();
- */
- /*
- XtVaSetValues( color_1, RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[0])), NULL );
- XtVaSetValues( color_2, RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[1])), NULL );
- XtVaSetValues( color_3, RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[2])), NULL );
- XtVaSetValues( color_4, RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[3])), NULL );
- XtVaSetValues( color_5, RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[4])), NULL );
- XtVaSetValues( color_6, RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[5])), NULL );
- XtVaSetValues( color_7, RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[6])), NULL );
- XtVaSetValues( color_8, RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[7])), NULL );
- XtVaSetValues( color_9, RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[8])), NULL );
- XtVaSetValues( color_10, RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[9])), NULL );
- XtVaSetValues( color_11, RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[10])), NULL );
- XtVaSetValues( color_12, RES_CONVERT( XmNbackground,
- GL_to_X_color_string(current_AGColors[11])), NULL );
- setup_palette();
- */
-
- color_found = FALSE;
- for (i=0; i<N_PALETTE; i++) {
- /*
- XStoreColor (UxDisplay, sys_cmap, &palette_colors[i]);
- */
- if ((AGColor[0] == current_AGColors[i][0]) &&
- (AGColor[1] == current_AGColors[i][1]) &&
- (AGColor[2] == current_AGColors[i][2])) {
- color_found = TRUE;
- isav = i;
- }
- }
- if (color_found) {
- activate_color (isav);
- }
- else {
- xcolorstring = GL_to_X_color_string (AGColor);
- /* printf ("Color %s not found in palette.\n", xcolorstring); */
- if (!XParseColor (UxDisplay, sys_cmap,
- xcolorstring, &palette_colors[11])) {
- sprintf(msgstring, "problem parsing color %s\n", xcolorstring);
- DialogType = 1;
- popup_Message();
- activate_color (0);
- goto POPUP;
- }
- XStoreColor (UxDisplay, sys_cmap, &palette_colors[11]);
- activate_color (11);
- }
- POPUP: UxPopupInterface (colorview, no_grab);
- CVwin = 99;
-
- /*
- UxPopdownInterface(Working);
- handleMotifInterfaceEvents();
- */
- }
-
- }
-
- void popdown_colorview()
- {
- XmListDeselectAllItems (browser_sl);
- XmListSetPos (browser_sl, 1);
- UxPopdownInterface (colorview);
- CVwin = -1;
- }
-
- char* GL_to_X_color_string (color)
- float color[3];
- {
- int rhex,ghex,bhex;
- static char color_string_buf[32];
-
- rhex = (int) (color[0] * 255);
- ghex = (int) (color[1] * 255);
- bhex = (int) (color[2] * 255);
- sprintf (color_string_buf, "#%02x%02x%02x", rhex, ghex, bhex);
- /* printf (" %s\n", color_string_buf); */
- return color_string_buf;
- }
-
- static void X_to_GL_color (color, glcolor)
- XColor* color;
- float glcolor[3];
- {
- double rval,gval,bval;
-
- rval = (double) color->red * 255 / 65535;
- gval = (double) color->green * 255 / 65535;
- bval = (double) color->blue * 255 / 65535;
- glcolor[0] = (float) rval / 255.0;
- glcolor[1] = (float) gval / 255.0;
- glcolor[2] = (float) bval / 255.0;
-
- /* printf("R = %f G = %f B = %f\n", glcolor[0], glcolor[1], glcolor[2]); */
- }
-
- Boolean GLParseColor (input_string, color_string_buf)
- char *input_string;
- char *color_string_buf;
- {
- char *newname;
- int rhex, ghex, bhex;
- double r, g, b;
- char s[2];
- char **ptr;
- char *red_string, *grn_string, *blu_string;
- int len;
- int i;
-
- newname = (char *)malloc( sizeof(char) * (strlen(input_string)+1));
- red_string = (char *)malloc(sizeof(char) * 32);
- grn_string = (char *)malloc(sizeof(char) * 32);
- blu_string = (char *)malloc(sizeof(char) * 32);
- ptr = (char **)malloc(sizeof(char) * 100);
-
- newname[0] = '\0';
- strcpy(newname, input_string);
- red_string[0] = '\0';
- grn_string[0] = '\0';
- blu_string[0] = '\0';
- strcpy(s," ");
- red_string = strtok(newname, s);
- grn_string = strtok(NULL, s);
- blu_string = strtok(NULL, s);
- if((red_string == NULL) || (grn_string == NULL) || (blu_string == NULL))
- goto ERROR;
- len = strlen(red_string);
- for(i=0; i<len; i++)
- if((isdigit(red_string[i]) == 0) && (red_string[i] != '.'))
- goto ERROR;
- len = strlen(grn_string);
- for(i=0; i<len; i++)
- if((isdigit(grn_string[i]) == 0) && (grn_string[i] != '.'))
- goto ERROR;
- len = strlen(blu_string);
- for(i=0; i<len; i++)
- if((isdigit(blu_string[i]) == 0) && (blu_string[i] != '.'))
- goto ERROR;
- r = strtod (red_string, ptr);
- g = strtod (grn_string, ptr);
- b = strtod (blu_string, ptr);
- /* printf ("r g b = %.2f %.2f %.2f ", r, g, b); */
-
- rhex = (int) (r * 255);
- ghex = (int) (g * 255);
- bhex = (int) (b * 255);
- /* printf ("rhex ghex bhex = %03d %03d %03d\n", rhex, ghex, bhex); */
- if( ((rhex>=0) && (rhex<=255)) &&
- ((ghex>=0) && (ghex<=255)) &&
- ((bhex>=0) && (bhex<=255)) ) {
- sprintf (color_string_buf, "#%02x%02x%02x", rhex, ghex, bhex);
- /* printf (" %s\n", color_string_buf); */
- /*
- free(newname);
- free(ptr);
- free(red_string);
- free(grn_string);
- free(blu_string);
- */
- return(TRUE);
- }
- else {
- /*
- ERROR: free(newname);
- free(ptr);
- free(red_string);
- free(grn_string);
- free(blu_string);
- */
- ERROR: return(FALSE);
- }
- }
-
- /*******************************************************************************
- END OF FILE
- *******************************************************************************/
-
-